// JavaScript Document

 $(function() {
			
	$( "#loan-range" ).slider({
		range: "min",
		value: 1000,
		step: 100,
		min:300,
		max: 2000,
		slide: function( event, ui ) {
		
					$("#amount").val(ui.value);
					var amount = ui.value ;
			  		var term = $( "#term-range" ).slider( "value" );
		 			update_payment(amount,term);
					
				}
		});
	  $( "#amount" ).val( $( "#loan-range" ).slider( "value" ) );	
	  
	  $( "#term-range" ).slider({
		range: "min",
		value: 6,
		min:1,
		max: 6,
		slide: function( event, ui ) {
					$("#term").val( ui.value);
					var amount = $( "#loan-range" ).slider( "value" ); 
			  		var term = ui.value ;
		 			update_payment(amount,term);
					
				}
		});
	  $( "#term" ).val(  $( "#term-range" ).slider( "value" ) );			
	  
	  $("#amount").val(300);
          $("#term").val(1);
          $("#amount-label").text(300);
          $("#month-label").text(1);
	  
	  update_payment( $( "#loan-range" ).slider( "value" ), $( "#term-range" ).slider( "value" ));
	  
	  });
	  
	  function update_payment(amount,term){
		  var estFee = amount*0.2;
		  var monthly = term*(amount*0.04);
		  var noWeeks = (term*30)/7;
		  var total = amount+estFee+monthly;
		  
		  $("#total_repayment").text(total);
		   $("#weekly_repayment").val(Math.floor(total/noWeeks)); 
		   $('#due_month').val(term);
		   $('#LoanAmount').val(amount); 
		   
		    $('#loan-range a').html('$ '+amount+' ');
			
         $('#term-range a').html(''+term+'');
		  
		   
	  }
	  
	  function launchApplication(){
		  var amount = $( "#loan-range" ).slider( "value" ); 
		  window.open('apply-now.php?amount='+amount);
		  
	  }